package com.eveinfo.tools;

import android.content.Context;
import android.content.SharedPreferences;

public class EveInfoPreferences {

	private static final String PREFS_NAME = "EveInfoPrefs";

	private static final String PREFS_ASSETS_IMAGE_SIZE = "assetsImageSize";
	public static final int ASSETS_IMAGE_SIZE_32 = 32;
	public static final int ASSETS_IMAGE_SIZE_64 = 64;

	private static final String PREFS_ENABLE_CACHE = "enableCache";

	private static final String PREFS_CACHE_ONLY = "cacheOnly";

	private static final String PREFS_CHECK_DATABASES = "cacheOnly";

	private int assetsImageSize;
	private boolean enableCache;
	private boolean cacheOnly;
	private boolean checkDatabases;

	private final Context context;

	public EveInfoPreferences(Context context) {
		this.context = context;
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		this.assetsImageSize = settings.getInt(PREFS_ASSETS_IMAGE_SIZE, ASSETS_IMAGE_SIZE_64);
		this.enableCache = settings.getBoolean(PREFS_ENABLE_CACHE, true);
		this.cacheOnly = settings.getBoolean(PREFS_CACHE_ONLY, false);
		this.checkDatabases = settings.getBoolean(PREFS_CHECK_DATABASES, true);

	}

	public int getAssetsImageSize() {
		return assetsImageSize;
	}

	public void setAssetsImageSize(int assetsImageSize) {
		this.assetsImageSize = assetsImageSize;
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putInt(PREFS_ASSETS_IMAGE_SIZE, assetsImageSize);
		editor.commit();
	}

	public boolean isEnableCache() {
		return enableCache;
	}

	public void setEnableCache(boolean enableCache) {
		this.enableCache = enableCache;
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean(PREFS_ENABLE_CACHE, enableCache);
		editor.commit();
	}

	public boolean isCacheOnly() {
		return cacheOnly;
	}

	public void setCacheOnly(boolean cacheOnly) {
		this.cacheOnly = cacheOnly;
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean(PREFS_CACHE_ONLY, cacheOnly);
		editor.commit();
	}

	public boolean isCheckDatabases() {
		return checkDatabases;
	}

	public void setCheckDatabases(boolean checkDatabases) {
		this.checkDatabases = checkDatabases;
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean(PREFS_CHECK_DATABASES, checkDatabases);
		editor.commit();
	}

}
